import modelEntity from "./modelEntity";
export default class RoleTemplate extends modelEntity {
  constructor(options) {
    super(options);
    this.RoleTemplateType = options.RoleTemplateType;
    this.Name = options.Name;
    this.PrjAccess = options.PrjAccess;
    this.MethodAccess = options.MethodAccess;
    this.MethodAccessDict = { view: false, modify: false };
    if (this.MethodAccess) {
      this.MethodAccessDict = JSON.parse(this.MethodAccess)
    }
    this.IsManager = options.IsManager;

    this.Remark = options.Remark;  //用于记录所属部门
  }
  static newInstance() {
    return new RoleTemplate({
      Name: null,
      RoleTemplateType: null,
      PrjAccess: null,
      MethodAccess: null,
      MethodAccessDict: { view: false, modify: false },
      IsManager: null,
    })
  }
  static loadList() {
    return new Promise((resolve, reject) => {
      getApp().globalData.api.http_get(`${getApp().globalData.baseUrl}/api/sys/roletemplate`)
        .then(
          res => {
            console.log(res);
            let list = [];
            res.forEach(x => {
              list.push(new RoleTemplate(x));
            });
            resolve(list);
          }
        )
    })
  }
  create() {
    return new Promise((resolve, reject) => {
      window.api.http_post("/api/sys/roletemplate", this)
        .then(
          res => {
            let model = new RoleTemplate(res);
            resolve(model);
          }
        )
    })
  }
  delete() {
    return new Promise((resolve, reject) => {
      window.api.http_delete("/api/sys/roletemplate", this)
        .then(
          res => {
            resolve(res);
          }
        )
    })
  }
  modify() {
    return new Promise((resolve, reject) => {
      window.api.http_put("/api/sys/roletemplate", this)
        .then(
          res => {
            let model = new RoleTemplate(res);
            resolve(model);
          }
        )
    })
  }
}
